<?php
class Ecore_Db extends Zend_Db
{
	var $db = null;
	var $stmt = null;

	public function __construct($objDb = null)
	{
		
	}

	public function prepare($strStore, $objDb = null)
	{
		if ($objDb == null) {
			$this->db = Zend_Registry::get('objDb');			
		} else {
			$this->db = $objDb;
		}
		$this->stmt = $this->db->prepare($strStore);
	}
	
	public function query($strSql)
	{
		$this->db = Zend_Registry::get('objDb');
		$this->stmt = $this->db->query($strSql);
	}

	public function execute()
	{
		$intResult = $this->stmt->execute();
		$this->stmt->closeCursor();
		$this->db->closeConnection();
		return $intResult;
	}

	public function closeCursor()
	{
		$this->stmt->closeCursor();
	}

	public function closeConnection()
	{
		if ($this->db) {
			$this->db->closeConnection();
		}
	}

	public function fetchAll($isCloseCursor = true)
	{
		$intResult = $this->stmt->execute();
		if ($intResult)	{
			$arrResult[] = $this->stmt->fetchAll();			
			if ($isCloseCursor == true)	{
				$this->stmt->closeCursor();
				$this->db->closeConnection();
			}
			return (isset($arrResult[1]) ? $arrResult : $arrResult[0]);
		}
		return null;	
	}

	public function bindParam($parameter, &$variable, $type = null, $length = null)
	{
		$this->stmt->bindParam($parameter, $variable, $type, $length);
	}
}
?>